<?php

namespace App\Http\Resources;

use App\Helpers\BaseResource;

class MoneyLog extends BaseResource
{
    public function toArray($request)
    {
        return $this->filterFields([
            'money' => $this->money,
            'type' => \App\Models\MoneyLog::TYPE[$this->type],
            'desc' => $this->desc,
            'time' => (string)$this->created_at,
            'state' => $this->setState(),
            'state_key' => $this->money > 0 ? 1 : 0
        ]);
    }

    private function setState()
    {
        if ($this->money > 0) {
            $state = "已发放";
        } else {
            $state = "已扣除";
        }

        return $state;

    }
}
